﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using SPCFMedicineInformer.Helpers;

namespace SPCFMedicineInformer.UserControls
{
    public partial class Consultation : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDates();
                ShowPlaceHolder(plcStep1);
            }
            

        }
        void LoadDates()
        {
            DateTime dteDefault = DateTime.Parse("1/1/2012");
            DataTable dtMonth = new DataTable();
            DataTable dtDay = new DataTable();
            DataTable dtYear = new DataTable();
            DataRow dr = null;

            dtMonth.Columns.Add(new DataColumn("TextField"));
            dtMonth.Columns.Add(new DataColumn("ValueField"));
            dtDay = dtMonth.Copy();
            dtYear = dtMonth.Copy();

            string textField = "TextField";
            string valueField = "ValueField";

            dr = dtMonth.NewRow();
            dr[textField] = "Month";
            dr[valueField] = "00";

            for (int mon = 1; mon <= 12;mon++)
            {
                dr = dtMonth.NewRow();
                dr[textField] = dteDefault.ToString("MMMM");
                dr[valueField] = mon;
                dtMonth.Rows.Add(dr);
                dteDefault = dteDefault.AddMonths(1);
            }

            
            dr = dtDay.NewRow();
            dr[textField] = "Day";
            dr[valueField] = "00";
            dtDay.Rows.Add(dr);
            for (int day = 1;day <= 31;day++)
            {
                dr = dtDay.NewRow();
                dr[textField] = day;
                dr[valueField] = day;
                dtDay.Rows.Add(dr);
            }
                
            dr = dtYear.NewRow();
            dr[textField] = "Year";
            dr[valueField] = "1900";
            dtYear.Rows.Add(dr);
            for(int year = DateTime.Now.Year ;year >= DateTime.Now.AddYears(-85).Year;year--)
            {
                dr = dtYear.NewRow();
                dr[textField] = year;
                dr[valueField] = year;
                dtYear.Rows.Add(dr);
            }

            FormHelper.BindDropDown(ddlDay, dtDay, textField, valueField);
            FormHelper.BindDropDown(ddlMonth, dtMonth, textField, valueField);
            FormHelper.BindDropDown(ddlYear, dtYear, textField, valueField);
        }
        protected void btnStepSubmit_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            if (btn.ID == "btnStep1Submit")
                ShowPlaceHolder(plcStep2);
            else if (btn.ID == "btnStep2Submit")
                ShowPlaceHolder(plcStep3);
        }
        void ShowPlaceHolder(PlaceHolder plc)
        {
            plcStep1.Visible = false;
            plcStep2.Visible = false;
            plcStep3.Visible = false;
            plc.Visible = true;
        }
    }
}